package com.qf.controller;

import com.qf.pojo.Device;
import com.qf.service.DeviceService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    DeviceService deviceService;

    //分页查所有
    @GetMapping("/deviceSelectAll")
    public ResultMsg selectAll(@RequestParam(value = "page",required = false,defaultValue = "1") int page,@RequestParam(value = "limit",required = false,defaultValue = "10") int limit){
        return deviceService.selectAll(page,limit);
    }

    //查一个设备
    @GetMapping("/deviceSelectOne")
    public ResultMsg selectOne(int deviceId){
        return deviceService.selectOne(deviceId);
    }

    //修改一个设备信息
    @PutMapping("/deviceUpdate")
    public ResultMsg update(@RequestBody Device device){
        return deviceService.update(device);
    }

    //新增一个设备
    @PostMapping("/deviceInsert")
    public ResultMsg insert(@RequestBody Device device){
        return deviceService.insert(device);
    }
    //删除一个设备
    @DeleteMapping("/deviceDeleteOne")
    public ResultMsg deleteOne(@RequestBody Map<String,Integer> map){
        return deviceService.deleteOne(map.get("deviceId"));
    }
    //删除多个设备
    @DeleteMapping("/deviceDeleteMul")
    public ResultMsg deleteMul(@RequestBody Map<String, List<Integer>> map){
        return deviceService.deleteMul(map.get("deviceIds"));
    }

    //分页模糊查
    @GetMapping("/deviceSelectDim")
    public ResultMsg selectDim(@RequestParam(value = "page",required = false,defaultValue = "1") int page,@RequestParam(value = "limit",required = false,defaultValue = "10") int limit,String deviceName,Integer deviceStatus){
        return deviceService.selectDim(page,limit,deviceName,deviceStatus);
    }

    //修改一个设备信息
    @GetMapping("/deviceUpdateStatus")
    public ResultMsg updateStatus(Integer deviceId,String deviceStatus){
        return deviceService.updateStatus(deviceId,deviceStatus);
    }

    //修改多个设备信息
    @PutMapping("/deviceUpdateStatusMul")
    public ResultMsg updateStatusMul(@RequestBody Map<String,Object> map){
        return deviceService.updateStatusMul((List<Integer>)map.get("deviceIds"),(Integer)map.get("deviceStatus"));
    }
}
